package cn.turing.ui;

import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.WindowConstants;

import cn.turing.db.MyDB;
import cn.turing.model.Student;

public class LoginFrame  extends JFrame
{
	private static final long serialVersionUID = 7305643042548754587L;

	JButton btnLogin;
	JButton btnCancel;
	JTextField txtUsername;
	JPasswordField txtPassword;
	MyDB myDB=new MyDB();
	public LoginFrame()
	{
		setSize(300,200);
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
		setResizable(false);
		setLocationRelativeTo(null);
		setTitle("登录");
		
		
		JLabel lblUsername=new JLabel("账号:");
		JLabel lblPassword=new JLabel("密码:");
		
		txtUsername=new JTextField(30);
		txtPassword=new JPasswordField(30);
		
		JPanel panelUsername=new JPanel();
		panelUsername.add(lblUsername);
		panelUsername.add(txtUsername);
		
		JPanel panelPassword=new JPanel();
		panelPassword.add(lblPassword);
		panelPassword.add(txtPassword);

		
		btnLogin=new JButton("确定");
		btnCancel=new JButton("取消");
		
		JPanel btnPanel=new JPanel();
		btnPanel.add(btnLogin);
		btnPanel.add(btnCancel);
		
		JPanel coutainer=new JPanel();
		coutainer.add(panelUsername);
		coutainer.add(panelPassword);
		coutainer.add(btnPanel);
		
		add(coutainer);
		addListeners();
		setVisible(true);
	}
	
	public void addListeners()
	{
		ActionListener btnLoginClick= new ActionListener() 
		{
			
			@Override
			public void actionPerformed(ActionEvent e)
			{
				Student student=new Student();
				student.setUsername(txtUsername.getText());
				
				int result=1;
				if(result>0)
				{
					JOptionPane.showMessageDialog(null, "登录成功");
					setVisible(false);
					
					MainFrame mainFrame =new MainFrame();
					mainFrame.setVisible(true);
				}
				else
					JOptionPane.showMessageDialog(null, "登录成功");
			}
		};
		btnLogin.addActionListener(btnLoginClick);
	}
}
